package com.yida.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.yida.interceptor.UserInterceptor;

@Configuration //定义此类为配置类，及相当于之前的xml文件
public class InterceptorConfig implements WebMvcConfigurer{

	//添加我们的拦截器
	 @Override
	public void addInterceptors(InterceptorRegistry registry) {  
		// TODO Auto-generated method stub
		 String[] excludePathPatterns = {"/admin","/admin/login"};
		WebMvcConfigurer.super.addInterceptors(registry);
		//已经提供了拦截器注册类 放进来相当于定义了一个bean
		registry.addInterceptor(new UserInterceptor()).addPathPatterns("/admin/**").excludePathPatterns(excludePathPatterns);
	}
	 
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// TODO Auto-generated method stub
		WebMvcConfigurer.super.addResourceHandlers(registry);
		registry.addResourceHandler("/blog/imgphoto/**").addResourceLocations("file:"+System.getProperties().getProperty("user.home")+"/blog/imgphoto/");
	} 
	
	
	
}
